package top.wuyang.springboot3.schoolTimetable.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.wuyang.springboot3.base.PageBean;
import top.wuyang.springboot3.base.R;
import top.wuyang.springboot3.schoolTimetable.dao.TbSubjectMapper;
import top.wuyang.springboot3.schoolTimetable.entity.TbSubject;
import top.wuyang.springboot3.schoolTimetable.service.TbSubjectService;
import top.wuyang.springboot3.validate.CommonValidate;
import top.wuyang.springboot3.vo.PageVO;

import java.util.List;

@RestController
@RequestMapping("/subject")
@RequiredArgsConstructor
public class TbSubjectController{

    private final TbSubjectService tbSubjectService;

    @GetMapping("/{pn}/{ps}")
    public R<PageVO<TbSubject>> query(@PathVariable("pn") Long pageNumber,@PathVariable("ps") Long pageSize, TbSubject tbSubject){
        return tbSubjectService.query(PageBean.instance(pageNumber,pageSize),tbSubject);
    }

    @GetMapping("/{id}")
    public R<TbSubject> queryById(@PathVariable("id") Integer id){
        return tbSubjectService.queryById(id);
    }

    @PostMapping("")
    public R<String> insert(@RequestBody @Validated(CommonValidate.Add.class) TbSubject tbSubject){
        return tbSubjectService.insert(tbSubject);
    }

    @PutMapping("")
    public R<String> update(@RequestBody @Validated(CommonValidate.Edit.class) TbSubject tbSubject){
        return tbSubjectService.update(tbSubject);
    }

    @DeleteMapping("/{id}")
    public R<String> delete(@PathVariable("id") Integer id){
        return tbSubjectService.delete(id);
    }



}
